﻿using HZU.ZP.Data.Interfaces;
using HZU.ZP.Data.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HZU.ZP.Data.Impl
{
    public class CollectRecordDao:ICollectRecordDao
    {
        private EFCoreDbContext _context;
        public CollectRecordDao(EFCoreDbContext context)
        {
            _context = context;
        }

        public void Add(CollectRecord collectRecord)
        {
            _context.CollectRecords.Add(collectRecord);
            _context.SaveChanges();
        }

        public void Delete(int appliacntId, int positionId)
        {
            var collectRecord = _context.CollectRecords.FirstOrDefault(e => e.ApplicantId == appliacntId && e.PositionId == positionId);
            _context.CollectRecords.Remove(collectRecord);
            _context.SaveChanges();
        }

        public CollectRecord Get(int appliacntId, int positionId)
        {
            return _context.CollectRecords.FirstOrDefault(e => e.ApplicantId == appliacntId && e.PositionId == positionId);
        }

        public IList<Position> Get(string sql)
        {
            return _context.Positions.FromSql(sql).OrderByDescending(e => e.CreateTime).ToList();
        }
    }
}
